import type { TableColumn } from '@/framework/components/core/super-table';
import dayjs from 'dayjs';
import { i18n } from '@/locales';

export type TableListItem = {
  id;
  name;
  deviceType;
  useType;
  userName;
  createTime;
  count;
  createTimeBtw;
};
export type TableColumnItem = TableColumn<TableListItem>;
// 设备类型
export const devicetypeList = [
  { id: 1, name: '未知' },
  { id: 9, name: '定位仪' },
  { id: 25, name: '手持机' },
  { id: 41, name: '交接仓' },
  { id: 49, name: '射频打印机' },
];
// 使用类型
export const useTypeList = [
  { id: 1, name: '默认/未知' },
  { id: 2, name: '样本入库' },
  { id: 3, name: '样本出库' },
  { id: 4, name: '样本核销' },
  { id: 5, name: '盘点' },
  { id: 6, name: '入库核查' },
  { id: 7, name: '样本定位' },
  { id: 8, name: '保藏标签打印' },
  // @ts-ignore
  { id: 9, name: `${i18n.global.t('specimen.Type_of_test_tube_box')}标签打印` },
  { id: 10, name: '暂存样本标签打印' },
  { id: 11, name: '样本移库' },
];
export const baseColumns: TableColumnItem[] = [
  {
    type: 'seq',
    title: '序号',
    width: 60,
  },
  {
    // @ts-ignore
    title: '设备sn/名称',
    field: 'name',
    searchField: 'nameLike',
  },
  {
    title: '设备类型',
    field: 'deviceType',
    formatter: ({ cellValue }) => {
      const obj = devicetypeList.find((item) => item.id === cellValue);
      const state = obj ? obj.name : '未知';
      return state;
    },
    formItemProps: {
      component: 'Select',
      componentProps: {
        options: devicetypeList.slice(1).map((item) => ({
          label: item.name,
          value: item.id,
        })),
      },
    },
  },
  {
    title: '使用类型',
    field: 'useType',
    formatter: ({ cellValue }) => {
      const obj = useTypeList.find((item) => item.id === cellValue);
      const state = obj ? obj.name : '未知';
      return state;
    },
    hideInSearch: true,
  },
  {
    title: '使用人',
    field: 'userName',
    searchField: 'userNameLike',
  },
  // 搜索
  {
    title: '创建时间',
    field: 'createTimeBtw',
    formItemProps: {
      component: 'RangePicker',
      componentProps: {
        valueFormat: 'YYYY-MM-DD',
      },
    },
    hideInTable: true,
  },
  {
    title: '使用时间',
    field: 'createTime',
    formatter: ({ cellValue }) => {
      return cellValue ? dayjs(cellValue).format('YYYY-MM-DD HH:mm:ss') : '-';
    },
    hideInSearch: true,
  },
  {
    title: '操作数量',
    field: 'count',
    hideInSearch: true,
  },
];
